package com.atguigu.gmall.list.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.SearchService;
import com.atguigu.gmall.model.list.Goods;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.management.relation.RelationSupport;

@Api(tags = "搜索管理")
@RestController
@RequestMapping("/api/list")
public class ListApiController {


    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;
    @Autowired
    private SearchService searchService;


    //ES Mapping映射
    @ApiOperation("//ES Mapping映射")
    @GetMapping("/inner/createIndex")
    public Result createIndex(){
        elasticsearchRestTemplate.createIndex(Goods.class);
        elasticsearchRestTemplate.putMapping(Goods.class);
        return Result.ok();
    }
    //上架商品
    @GetMapping("/inner/upperGoods/{skuId}")
    public Result upperGoods(@PathVariable(name = "skuId") Long skuId){
        searchService.upperGoods(skuId);

        return Result.ok();
    }
    //下架商品
    @GetMapping("/inner/lowerGoods/{skuId}")
    public Result lowerGoods(@PathVariable(name = "skuId") Long skuId){

        searchService.lowerGoods(skuId);
        return Result.ok();
    }
    //热点
    @GetMapping("/inner/hotScore/{skuId}")
    public Result hotScore(@PathVariable(name = "skuId") Long skuId){


        searchService.hotScore(skuId);

        return Result.ok();

    }

    @PostMapping
    public Result list(@RequestBody SearchParam searchParam) throws Exception{
        SearchResponseVo responseVo = searchService.search(searchParam);
        return Result.ok(responseVo);
    }
}
